package com.hoshiicloud.commissioncalculation.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.commissioncalculation.entity.TradeFlow;
import com.hoshiicloud.commissioncalculation.param.TradeFlowQueryParam;
import com.hoshiicloud.commissioncalculation.service.TradeFlowService;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.goods.entity.sku.ExtSku;
import com.hoshiicloud.goods.param.sku.ExtSkuQueryParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.hoshiicloud.common.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * 总流水表(TradeFlow)表控制层
 *
 * @author makejava
 * @since 2019-09-05 14:40:22
 */
@RestController
@RequestMapping("/tradeFlow")
@Slf4j
public class TradeFlowController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private TradeFlowService tradeFlowService;

	/**
	 * @param param
	 * @return com.hoshiicloud.common.rpc.Response
	 * @description: 分页查询扩展商品SKU
	 */
	@ApiOperation(value = "分页查询流水列表")
	@PostMapping("/query/page")
	public Response<IPage<TradeFlow>> page(@RequestBody @Valid TradeFlowQueryParam param) {
		try {
			log.info("分页查询扩展商品SKU");
			QueryWrapper<ExtSku> queryWrapper = new QueryWrapper<ExtSku>();

			IPage<TradeFlow> page = new Page<>(Long.parseLong(param.getPageNumber()), Long.parseLong(param.getPageSize()));
			String key = "ExtSkuQueryParam{"+param.toString() + "},Page{pageNumber=" + param.getPageNumber() + ",pageSize=" + param.getPageSize() + "}";
			return Response.data(tradeFlowService.getPage(page, queryWrapper, key));
		} catch (Exception e) {
			log.error("分页查询扩展商品SKU异常", e);
			return Response.failed("分页查询扩展商品SKU异常");
		}
	}

}